package cn.wit.summit.chwan.widgets;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;

public class DetialImgRecycleView extends RecyclerView{
    public DetialImgRecycleView(Context context) {
        super(context);
    }

    public DetialImgRecycleView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public DetialImgRecycleView(Context context, @Nullable AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }


    float startx = 0, starty = 0, endx = 0, endy = 0;
    public boolean hastoch = false;

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        Log.e("xxx", "hlist " + ev.getAction());
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            getParent().requestDisallowInterceptTouchEvent(true);
            startx = ev.getX();
            starty = ev.getY();
            hastoch = true;
            Log.e("xxx", "hlist 触摸");
        } else if (ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_CANCEL) {
            Log.e("xxx", "hlist 去掉触摸");
            hastoch = false;

        }

        if (ev.getAction() == MotionEvent.ACTION_MOVE) {
            if (Math.abs(startx - ev.getX()) > Math.abs(starty - ev.getY())) {
                Log.e("xxx", "hlist横向 true");
                onTouchEvent(ev);
//                getParent().requestDisallowInterceptTouchEvent(true);
                return true;
            } else {
                getParent().requestDisallowInterceptTouchEvent(false);
                return false;
            }

//            else {
//                getParent().requestDisallowInterceptTouchEvent(false);
//return false;
//            }
        }
        return super.dispatchTouchEvent(ev);
    }
}
